package com.ruoyi.system.wnjk.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.wnjk.domain.po.ShopLogisticsDetails;
import com.ruoyi.system.wnjk.domain.po.ShopOrder;
import com.ruoyi.system.wnjk.domain.po.TripartiteLogistics;
import com.ruoyi.system.wnjk.domain.vo.ShopLogisticsDetailsVo;
import com.ruoyi.system.wnjk.mapper.ShopLogisticsDetailsMapper;
import com.ruoyi.system.wnjk.service.IShopLogisticsDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 订单物流详情Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-05
 */
@Service
public class ShopLogisticsDetailsServiceImpl implements IShopLogisticsDetailsService
{
    @Autowired
    private ShopLogisticsDetailsMapper shopLogisticsDetailsMapper;


    @Autowired
    private TripartitleLogisticsService tripartitleLogisticsService;

    /**
     * 查询订单物流详情
     *
     * @param id 订单物流详情主键
     * @return 订单物流详情
     */
    @Override
    public ShopLogisticsDetails selectShopLogisticsDetailsById(Long id)
    {
        return shopLogisticsDetailsMapper.selectShopLogisticsDetailsById(id);
    }

    /**
     * 查询订单物流详情列表
     *
     * @param shopLogisticsDetails 订单物流详情
     * @return 订单物流详情
     */
    @Override
    public List<ShopLogisticsDetails> selectShopLogisticsDetailsList(ShopLogisticsDetails shopLogisticsDetails)
    {
        return shopLogisticsDetailsMapper.selectShopLogisticsDetailsList(shopLogisticsDetails);
    }

    /**
     * 新增订单物流详情
     *
     * @param shopLogisticsDetails 订单物流详情
     * @return 结果
     */
    @Override
    public int insertShopLogisticsDetails(ShopLogisticsDetails shopLogisticsDetails)
    {
        shopLogisticsDetails.setCreateTime(DateUtils.getNowDate());
        return shopLogisticsDetailsMapper.insertShopLogisticsDetails(shopLogisticsDetails);
    }

    /**
     * 修改订单物流详情
     *
     * @param shopLogisticsDetails 订单物流详情
     * @return 结果
     */
    @Override
    public int updateShopLogisticsDetails(ShopLogisticsDetails shopLogisticsDetails)
    {
        return shopLogisticsDetailsMapper.updateShopLogisticsDetails(shopLogisticsDetails);
    }

    /**
     * 批量删除订单物流详情
     *
     * @param ids 需要删除的订单物流详情主键
     * @return 结果
     */
    @Override
    public int deleteShopLogisticsDetailsByIds(Long[] ids)
    {
        return shopLogisticsDetailsMapper.deleteShopLogisticsDetailsByIds(ids);
    }

    /**
     * 删除订单物流详情信息
     *
     * @param id 订单物流详情主键
     * @return 结果
     */
    @Override
    public int deleteShopLogisticsDetailsById(Long id)
    {
        return shopLogisticsDetailsMapper.deleteShopLogisticsDetailsById(id);
    }

    @Override
    public ShopLogisticsDetailsVo getLogisticsDetailsById(Long id) {
        ShopLogisticsDetailsVo shopLogisticsDetailsVo = shopLogisticsDetailsMapper.getLogisticsDetailsById(id);
        String logisticsId = shopLogisticsDetailsVo.getLogisticsId();
        String phone = shopLogisticsDetailsVo.getPhone();
//        System.out.println(shopLogisticsDetailsVo);
//        System.out.println("logisticsId = "+logisticsId);
//        System.out.println("phone = "+phone);
        TripartiteLogistics logistics = tripartitleLogisticsService.getTripartiteLogistics(logisticsId, phone);
//        System.out.println(logistics.toString());
        if (logistics.getSuccess()){
            shopLogisticsDetailsVo.setTripartiteLogisticsData(logistics.getData());
        }
        return shopLogisticsDetailsVo;
    }

    @Override
    public void createLogistics(ShopOrder shopOrder) {
        //创建物流信息 todo
    }
}
